{extend name="platform/base" /}
{block name="main"}
<div class="m-b-md">
	<h3 class="m-b-none">修改模块</h3>
</div>
<section class="panel panel-default">
	<div class="panel-body">
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">模块名</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="module_name" value="{$module_info.module_name}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">上級菜单</label>
				<div class="col-sm-4">
					<select id="pid" name="account" class="form-control m-b">
						<option value="0">顶级菜单</option> 
						{foreach name="list" item="v1"}
						<option value="{$v1['data']['module_id']}" {if
							condition="$module_info.pid eq $v1['data']['module_id']"}selected{/if}>&nbsp;&nbsp;&nbsp;{$v1['data']['module_name']}</option>
						{foreach name="v1['sub_menu']" item="v2"}
						<option value="{$v2['module_id']}" {if
							condition="$module_info.pid eq $v2['module_id']"}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$v2['module_name']}</option>
						{/foreach} {/foreach}
					</select>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">控制器名</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="controller" value="{$module_info.controller}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">方法名</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="method" value="{$module_info.method}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">url</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="url" value="{$module_info.url}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                                            <label class="col-sm-2 control-label">是否是菜单</label>
                                            <div class="col-sm-4">
                                                <label class="switch">
                                                    <input id="is_menu" type="checkbox" {if condition="$module_info.is_menu eq 1" }checked="checked" {/if}>
                                                    <span></span> </label>
                                            </div>
                                        </div>
                                        
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                                            <label class="col-sm-2 control-label">是否控制权限</label>
                                            <div class="col-sm-4">
                                                <label class="switch">
                                                    <input id="is_control_auth" type="checkbox"{if condition="$module_info.is_control_auth eq 1" }checked="checked" {/if} >
                                                    <span></span> </label>
                                            </div>
                                        </div>
            <div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                                            <label class="col-sm-2 control-label">是否仅开发者模式可见</label>
                                            <div class="col-sm-4">
                                                <label class="switch">
                                                    <input id="is_dev" type="checkbox" {if condition="$module_info.is_dev eq 1" }checked="checked" {/if}>
                                                    <span></span> </label>
                                            </div>
                                        </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="sort" value="{$module_info.sort}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<!-- 上传图片 -->
			<div class="form-group">
	            <label class="col-sm-2 control-label">图片</label>
	            <div class="col-sm-2">
	            	<p class="imgLogo-box"><img id="imgLogo" src="__UPLOAD__/{$module_info['module_picture']}" class="imglogo"/></p>
	            	<a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
	            		<span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
	            		<input hidefocus="true" size="1" class="input-file" name="file_upload"
							id="uploadImg" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;"
							onchange="imgUpload(this);"> 
							<input type="hidden" id="Logo" value="{$module_info['module_picture']}" />
						</span>
						<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
					</a>
	            	
	            </div>
	        </div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">矢量图Class</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="icon_class" value="{$module_info.icon_class}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                                            <label class="col-sm-2 control-label">描述</label>
                                            <div class="col-sm-10">
                                                <div id="editor" class="form-control" style="overflow:scroll;height:150px;max-height:150px">{$module_info.desc}</div>
                                            </div>
                                        </div>
			<!-- 书签 -->
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<input type="hidden" id="module_id" value="{$module_info.module_id}" />
					<a href="javascript:void(0);" onclick="editModuleAjax()" class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>

	function editModuleAjax() {
		var module_id = $("#module_id").val();
		var pid = $("#pid").val();
		var module_name = $("#module_name").val();
		var controller = $("#controller").val();
		var method = $("#method").val();
		var url = $("#url").val();
		var is_menu = $("#is_menu").val();
		var is_control_auth = 1;//是否控制权限，默认：1，控制
		var is_dev = $("#is_dev").val();
		var sort = $("#sort").val();
		var desc = $("#editor").html();
		if ($("#is_menu").prop("checked")) {
			var is_menu = 1;
		} else {
			var is_menu = 0;
		}
		if(!$("#is_control_auth").prop("checked")){
			is_control_auth = 0;
		}
		if ($("#is_dev").prop("checked")) {
			var is_dev = 1;
		} else {
			var is_dev = 0;
		}
		var module_picture = $("#Logo").val();
		var icon_class = $('#icon_class').val();
// 		verify(module_name, controller, method, url, sort, desc);
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/System/editModule')}",
			data : {
				'module_id' : module_id,
				'pid' : pid,
				'module_name' : module_name,
				'controller' : controller,
				'method' : method,
				"url" : url,
				'is_menu' : is_menu,
				'is_control_auth' : is_control_auth,
				'is_dev' : is_dev,
				'sort' : sort,
				'module_picture' : module_picture,
				'desc' : desc,
				'icon_class' : icon_class
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', data['message'], "{:__URL('PLATFORM_MAIN/system/modulelist')}");
				} else {
					showMessage("error",data['message']);
				}
			}
		});
	}
	/**
	 *图片上传
	 */
	/*function imgUpload(event) {
		var fileid = $(event).attr("id");
		var str = $(event).next().attr("id");
		fileCommonUpload("UPLOAD_URL", fileid,"__UPLOAD__",str);
	}*/
	//图片上传
	function imgUpload(event) {
		var fileid = $(event).attr("id");
		var data = { 'file_path' : UPLOADADV };
		uploadFile(fileid,data,function(res){
			if(res.code){
				$("#imgLogo").attr("src",__IMG(res.data));
				$("#Logo").val(res.data);
				showTip(res.message,"success");
			}else{
				showTip(res.message,"error");
			}
		});
	}

	/**
	 *模块输入信息验证
	 */
	function verify(module_name, controller, method, url, sort, desc) {
		if (module_name == '') {
			$("#module_name").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		if (controller == '') {
			$("#controller").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		if (method == '') {
			$("#method").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		if (url == '') {
			$("#url").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		if (sort == '') {
			$("#sort").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		if (desc == '') {
			$("#desc").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
	}
</script>
{/block}
